function show_modal_dialog_all_record_onclick(p_goto_url,p_fuseaction,p_recordtype_filter,p_txt_obj,p_hdn_obj,p_fuseaction_back){

v_url = _DSP_MODAL_DIALOG_URL_PATH;
	v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_recordtype_filter_list=" + p_recordtype_filter);
	v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
	v_url = v_url+ "&" + randomizeNumber();
	sRtn = showModalDialog(v_url,"","dialogWidth=450pt;dialogHeight=500pt;dialogTop=80pt;status=no;scroll=no;");
	//alert(sRtn);
	if (!sRtn) return;
	arr_value = sRtn.split(_LIST_DELIMITOR);
	p_hdn_obj.value = arr_value[1];
	p_txt_obj.value = arr_value[1];
	//alert(p_hdn_obj.value);
	//alert(p_txt_obj.value);
	if (p_fuseaction_back!=""){
		document.forms(0).fuseaction.value = p_fuseaction_back;
		document.forms(0).submit();
	}
}
///Luu lai danh sach cac the va cac gia tri co trong form
function save_list_onclick(f,hdn_obj_tag,hdn_obj_value){
	//alert('tttt');
	var list_tag = "";
	var list_value = "";
	var v_temp = "";
	var v_value = "";
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		if (e.value==""||e.value==null){
			v_value=" ";
		}else{
			v_value=e.value;
		}
		if (e.xml_tag_in_db &&(e.type!='radio' && e.type!='checkbox')){
			list_tag = list_append(list_tag,e.xml_tag_in_db,_SUB_LIST_DELIMITOR);
			list_value = list_append(list_value,v_value,_SUB_LIST_DELIMITOR);
		}
		if (e.xml_tag_in_db &&(e.type=='radio' || e.type=='checkbox')){
			list_tag = list_append(list_tag,e.xml_tag_in_db,_SUB_LIST_DELIMITOR);
			if (e.checked==true){
				v_temp="true";
			}else{
				v_temp="false";
			}
			list_value = list_append(list_value,v_temp,_SUB_LIST_DELIMITOR);
		}
	}

	if (hdn_obj_tag.value!=null && hdn_obj_value.value!=null){
		hdn_obj_tag.value = list_tag;
		hdn_obj_value.value = list_value;
	}
}

function save_hidden_multiple_list(p_chk_obj,the_separator){
	var ret = "";
	try{
		if (!p_chk_obj.length){
			if (p_chk_obj.checked){
				ret=p_chk_obj.value;
				eval('document.forms(0).'+p_chk_obj.xml_tag_in_db_name+'.value="'+ret+'"');
				//alert('document.forms(0).'+p_chk_obj.xml_tag_in_db_name+'.value="'+ret+'"');
			}
		}else{	
			current_chk_obj = p_chk_obj[0].xml_tag_in_db_name;
			for(i=0;i<p_chk_obj.length;i++){
				next_chk_obj = p_chk_obj[i].xml_tag_in_db_name;	
				//alert(next_chk_obj);
				if (current_chk_obj != next_chk_obj){  //Neu het danh sach thi gan vao gia tri cua danh sach
					eval('document.forms(0).'+current_chk_obj+'.value="'+ret+'"');
					ret = "";
				}
				if (p_chk_obj[i].checked){
					ret=list_append(ret,p_chk_obj[i].value,the_separator);					
				}
				if (i==p_chk_obj.length-1){ //Cuoi gan gia tri vao danh sach
					eval('document.forms(0).'+next_chk_obj+'.value="'+ret+'"');
					ret = "";
				}
				current_chk_obj = next_chk_obj;
				//alert(current_chk_obj);
			}
			
		}	
	}catch(e){;}
}
/////Begin/////Cac ham phuc vui cho checkbox multiple
function show_row_selected(rad_id,tr_name){
	//Thay doi selected cua radio button
	eval('document.all.' + rad_id + '(0).checked=false');
	eval('document.all.' + rad_id + '(1).checked=true');
	//hide cac dong chua modul neu tr_name='tr_function' va gia tri cua checked=""
	if (tr_name == 'tr_function'){
		v_count=eval('document.all.tr_modul.length');
		if (v_count){
			for(var i=0;i<v_count;i++){
				if (eval('document.all.tr_modul[i].checked == ""')){
					eval('document.all.tr_modul[i].style.display="none"');
				}else{
					eval('document.all.tr_modul[i].style.display="block"');
				}
			}
		}else{
			if (eval('document.all.tr_modul.checked == ""')){
				eval('document.all.tr_modul.style.display="none"');
			}else{
				eval('document.all.tr_modul.style.display="block"');
			}
		}
	}
	//hide cac dong tr_name neu gia tri checked=""
	v_count=eval('document.all.' + tr_name + '.length');
	var v_odd_class="";
	if(v_count){
		for(var i=0;i<v_count;i++){
			if (eval('document.all.' + tr_name + '[i].checked == ""')){
				eval('document.all.' + tr_name + '[i].style.display="none"');
			}else{
				if (v_odd_class == "odd_row"){
					eval('document.all.'+ tr_name + '[i].className="round_row"');
					v_odd_class = "round_row"
				}else{
					eval('document.all.'+ tr_name + '[i].className="odd_row"');
					v_odd_class = "odd_row"
				}
			}
		}
	}else{
		if (eval('document.all.' + tr_name + '.checked == ""')){
			eval('document.all.' + tr_name + '.style.display="none"');
		}else{
			if (v_odd_class == "odd_row"){
				eval('document.all.'+ tr_name + '.className="round_row"');
				v_odd_class = "round_row"
			}else{
				eval('document.all.'+ tr_name + '.className="odd_row"');
				v_odd_class = "odd_row"
			}
		}
	}
}
//Ham show_all_row co chuc nang hien thi tat ca doi tuong (ke ca khong thuoc nhom)
function show_row_all(rad_id,tr_name){
	//Thay doi selected cua radio button
	eval('document.all.' + rad_id + '(0).checked=true');
	eval('document.all.' + rad_id + '(1).checked=false');
	//show tat ca cac tr_modul neu tr_name='tr_function'
	if (tr_name == 'tr_function'){
		v_count=eval('document.all.tr_modul.length');
		if(v_count){
			for(var i=0;i<v_count;i++){
				var v_img_path = getImgDirectory(eval('document.all.img_modul[i].src'));
				eval('document.all.img_modul[i].src = v_img_path + "open.gif"');
				eval('document.all.tr_modul[i].style.display="block"');
			}
		}else{
			eval('document.all.tr_modul.style.display="block"');
		}
	}
	//show tat ca cac tr_name
	v_count=eval('document.all.' + tr_name + '.length');
	var v_odd_class="";
	if(v_count){
		for(var i=0;i<v_count;i++){
			eval('document.all.' + tr_name + '[i].style.display="block"');
			if (v_odd_class == "odd_row"){
				eval('document.all.'+ tr_name + '[i].className="round_row"');
				v_odd_class = "round_row"
			}else{
				eval('document.all.'+ tr_name + '[i].className="odd_row"');
				v_odd_class = "odd_row"
			}
		}
	}else{
		eval('document.all.' + tr_name + '.style.display="block"');
		if (v_odd_class == "odd_row"){
			eval('document.all.'+ tr_name + '.className="round_row"');
			v_odd_class = "round_row"
		}else{
			eval('document.all.'+ tr_name + '.className="odd_row"');
			v_odd_class = "odd_row"
		}
	}
}
/*Ham change_item_checked
Chuc nang: Xu ly khi NSD click mouse vao checkbox cua EndUser hoac cua Function
	-Tim tr_name chua checkbox duoc click va thay doi trang thai cua attribute checked ("" hoac "checked")
	-Kiem tra cac trang thai checked cua cac function trong modul de xac dinh trang thai checked cua modul
	(Neu khong co function nao duoc chon thi checked=""; neu co thi checked="checked")
	-Kiem tra che do hien thi (qua radio button) de refresh lai man hinh
Tham so:
	-chk_obj: doi tuong checkbox duoc click
	-tr_name: ten id cua row chua checkbox (tr_function hoac tr_enduser)
	-rad_id:  ten id cua radio button xac dinh che do hien thi cua moi loai (rad_group_enduser hoac rad_group_function)
*/
function change_item_checked(chk_obj,tr_name,rad_id){
	var v_count;
	var i;
	var v_modul_checked=false;
	//Tim row chua checkbox va thay doi gia tri cua tr_name.checked
	v_count = eval('document.all.' + tr_name +'.length');
	i=0;
	if (v_count){
		while (i<v_count){
			if (eval('document.all.' + tr_name + '[i].value == chk_obj.value')){
				if (eval('document.all.' + tr_name + '[i].checked == "checked"')){
					eval('document.all.' + tr_name + '[i].checked = ""');
				}else{
					eval('document.all.' + tr_name + '[i].checked = "checked"');
				}
				//break;
			}
			//Kiem tra xem trong mo dul co chuc nang nao duoc chon khong
			if (tr_name == 'tr_function'){
				if (eval('document.all.' + tr_name + '[i].modul == chk_obj.modul')){
					if (eval('document.all.' + tr_name + '[i].checked == "checked"')){
						v_modul_checked=true;
					}
				}
			}
			i++;
		}
	}else{
		if (eval('document.all.' + tr_name + '.value == chk_obj.value')){
			if (eval('document.all.' + tr_name + '.checked == "checked"')){
				eval('document.all.' + tr_name + '.checked = ""');
			}else{
				eval('document.all.' + tr_name + '.checked = "checked"');
			}
		}
		if (tr_name == 'tr_function'){
			if (eval('document.all.' + tr_name + '.modul == chk_obj.modul')){
				if (eval('document.all.' + tr_name + '.checked == "checked"')){
					v_modul_checked=true;
				}
			}
		}
	}
	//thay doi gia tri cua checked trong tr_modul va chk_modul_id theo v_modul_checked=True or False
	if (tr_name == 'tr_function'){
		v_count = eval('document.all.tr_modul.length');
		if (v_count){
			i=0;
			while (i<v_count){
				if (eval('document.all.tr_modul[i].value == chk_obj.modul')){
					if (v_modul_checked == true){
						eval('document.all.tr_modul[i].checked = "checked"');
						eval('document.all.chk_modul_id[i].checked = "checked"');
					}else{
						eval('document.all.tr_modul[i].checked = ""');
						eval('document.all.chk_modul_id[i].checked = ""');
					}
					break;
				}
				i++;
			}
		}else{
			if (eval('document.all.tr_modul.value == chk_obj.modul')){
				if (v_modul_checked == true){
					eval('document.all.tr_modul.checked = "checked"');
				}else{
					eval('document.all.tr_modul.checked = ""');
				}
			}
		}
	}
	//Kiem tra che do hien thi de refresh man hinh
	if (eval('document.all.' + rad_id + '(1).checked')){
		show_row_selected(rad_id,tr_name);
	}
}
function save_hidden_list_item_id(p_hdn_list,p_chk_obj){
	if (checkbox_value_to_list(p_chk_obj,",")!=""){
		p_hdn_list.value = checkbox_value_to_list(p_chk_obj,",");
//		alert(p_hdn_list.value);
	}
}
/////End/////Cac ham phuc vui cho checkbox multiple
function onchange_submit(obj_sel_type,obj_hdn_type,p_fuseaction){
	obj_hdn_type.value = obj_sel_type.value;
	btn_save_onclick(p_fuseaction);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//DATCQ Ham nay duoc bo sung thuc thi khi In giay bien nhan nhieu ho so, hien yeu cau nhap ten cua can bo xa ...
//Cap nhat lai 10/06/08

function show_window_to_print(p_goto_url,p_checkbox_obj,p_type,p_fuseaction) {
	var list = checkbox_value_to_list(p_checkbox_obj,",");
//DATCQ bo sung in danh sach bien nhan nhieu ho so
	var array_id_list = list.split(",");	//alert(array_id_list);
	var array_recordtype = new Array("015","016","017","018","019","020","021","022","023","024");
		
	if (list) {   //Kiem tra xem co cau hoi nao duoc chon hay khong?
		//if(list_count_element(list,",")==1)	{ //Kiem tra xem co phai chon 1 cau hoi hay khong?
		v_url = p_goto_url + "?hdn_record_id=" + list+ "&hdn_recordtype_filter=" + p_type +"&fuseaction="+p_fuseaction +"&modal_dialog_mode=1";
		
		if(p_fuseaction == "PRINT_RECORD_TO_SUBMIT"){
			if (list_count_element(list,",")==1){ //In trinh ky ho so
				v_url = p_goto_url + "?hdn_record_id=" + list+ "&hdn_recordtype_filter=" + p_type + "&fuseaction="+p_fuseaction +"&modal_dialog_mode=1";
				//In giay trinh ky (tai lieu kem theo don)
				if(p_type =="011"||p_type=="012"||p_type=="013"){
					//Hien thi bang dialog yeu cau nhap tai lieu kem theo cua ho so
					v_url = _DSP_MODAL_DIALOG_URL_PATH;
					v_url = v_url + "?goto_url=" + escape("record/handle/index.php?hdn_record_id=" + list + "&hdn_recordtype_filter=" + p_type);
					v_url = v_url + "&fuseaction=DISPLAY_DOCUMENT_INCLUDE&modal_dialog_mode=1" 
					v_url = v_url+ "&" + randomizeNumber();
					sRtn = showModalDialog(v_url,"","dialogWidth=600pt;dialogHeight=450pt;dialogTop=100pt;status=no;scroll=yes;");
					if(sRtn != 0){
						var p_exporttype = sRtn;
					}
				}
				v_url = p_goto_url + "?hdn_record_id=" + list+ "&hdn_recordtype_filter=" + p_type + "&hdn_exporttype=" + p_exporttype +"&fuseaction="+p_fuseaction +"&modal_dialog_mode=1";
			}
			else{
				alert("Chỉ chọn 1 hồ sơ.");	
				return;
			}
		}
		
		//Truong hop in bien nhan nhieu ho so cua phong noi vu
		else{
			if(p_fuseaction=="PRINT_RECORD_RECEIPT"){
				//alert(array_id_list.length+'/'+check_obj_in_arr(p_type,array_recordtype));
				if(array_id_list.length >1 && check_obj_in_arr(p_type,array_recordtype)!=true){
					alert("Chỉ chọn 1 hồ sơ.");	
					return;
				}
				
				if(array_id_list.length >1 && check_obj_in_arr(p_type,array_recordtype)==true){
					v_url = _DSP_MODAL_DIALOG_URL_PATH;
					v_url = v_url + "?goto_url=" + escape("record/receive/index.php?hdn_record_id=" + list + "&hdn_recordtype_filter=" + p_type);
					v_url = v_url + "&fuseaction=DISPLAY_NAME_RECEIPT&modal_dialog_mode=1" 
					v_url = v_url+ "&" + randomizeNumber();
					sRtn = showModalDialog(v_url,"","dialogWidth=400pt;dialogHeight=200pt;dialogTop=100pt;status=no;scroll=no;");
					if (!sRtn){ 	
						return;
					}else{
						arr_value = sRtn.split(_LIST_DELIMITOR);
						//alert(arr_value); //return;
						var name_staff_receipt = arr_value[0];
						var address_staff_receipt = arr_value[1];
						var date_receipt = arr_value[2];
					}
					v_url = p_goto_url + "?hdn_record_id=" + list+ "&hdn_recordtype_filter=" + p_type +"&fuseaction="+p_fuseaction+"&name_staff_receipt="+name_staff_receipt+"&address_staff_receipt="+address_staff_receipt+"&date_receipt="+date_receipt+"&modal_dialog_mode=1";
				}
			}
		}
		v_url = v_url+ "&" + randomizeNumber();
//		alert(v_url);
		goto_url(v_url,3);
		
	} else {
		alert("Chưa có hồ sơ nào được chọn.");
		return;		
	}
}

//DatCQ bo sung de kiem tra xem phan tu co nam trong mang hay ko ?
function check_obj_in_arr(p_obj,p_array){
//	alert(p_array.length);
	for(i = 0; i <p_array.length; i++)
	if( p_obj == p_array[i] )
		return true;
}

//DatCQ bo sung btn cap nhat ten can bo phuong, xa nop ho so
function btn_update_staff_name(p_txt_obj_1,p_txt_obj_2,p_txt_obj_3){
	if (verify(document.forms(0))){
		window.returnValue = p_txt_obj_1.value + _LIST_DELIMITOR + p_txt_obj_2.value + _LIST_DELIMITOR + p_txt_obj_3;
		window.close();
	}
}

function list_count_element(the_list,the_separator)
{	
	if (the_list=="") return -1;
	arr_value = the_list.split(the_separator);
	if (arr_value.length > 0){
			return arr_value.length;
	}
	return -1;
}	
//Chuyen toi url
function goto_url(p_url,p_open_new_win)
{
	if (p_open_new_win==3)
		open_me(p_url, 1, 1, 1, 1, 1, 0, 0, 0, 0, 450, 650, 0, 0);
	else{
		//document.parentWindow.location = p_url;	
		//alert (document.location);
		if (p_open_new_win==2)
			window.top.location = p_url;
		else{
			window.location = p_url;
		}
	}
}
//==============================================================================================================
// open new window with some value
function open_me(url, vStatus, vResizeable, vScrollbars, vToolbar,vMenubar, vLocation, vFullscreen, vTitlebar, vCentered, vHeight, vWidth, vTop, vLeft)	 
{
	winDef = '';
	winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('menubar=').concat((vMenubar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('height=').concat(vHeight).concat(',');
	winDef = winDef.concat('width=').concat(vWidth).concat(',');

	if (vCentered)	{
		winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
		winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	}
	else	{
		winDef = winDef.concat('top=').concat(vTop).concat(',');
		winDef = winDef.concat('left=').concat(vLeft);
	}
	open(url, '_blank', winDef);
}
//Ham de cap nhat cong viec (handle)
function btn_save_record_work_onclick(p_worktype_checkbox_obj,p_hdn_worktype_checkbox_obj, p_fuseaction){
	p_hdn_worktype_checkbox_obj.value = checkbox_value_to_list(p_worktype_checkbox_obj,",");
	btn_save_onclick(p_fuseaction);
}
function btn_add_record_work_onclick(p_obj, p_fuseaction, p_goto_url){
	if (_MODAL_DIALOG_MODE==1){
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + p_goto_url + "&hdn_item_id=0" + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" + "&" + randomizeNumber();
		sRtn = showModalDialog(v_url,"","dialogWidth=470pt;dialogHeight=210pt;status=no;scroll=no;");
		//alert(sRtn);
		document.forms(0).fuseaction.value = "";
		document.forms(0).submit();
	}else{
		document.forms(0).fuseaction.value = p_fuseaction;
		document.forms(0).submit();
	}	
}
function show_modal_dialog_update_onclick(p_goto_url,p_fuseaction,p_fuseaction_ret, p_checkbox_item, p_hdn_item,hdn_type,hdn_date){
//alert(p_goto_url+"*1*"+p_fuseaction+"*2*"+p_fuseaction_ret+"*3*"+checkbox_value_to_list(p_checkbox_item,",")+"*4*"+p_hdn_item.value+"*5*"+hdn_type.value+"*6*"+hdn_date.value +"*7*");
	var v_id_list = checkbox_value_to_list(p_checkbox_item,",");
	if (v_id_list) {  
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id_list=" + v_id_list + "&hdn_recordtype_filter=" + hdn_type.value+ "&hdn_received_date=" + hdn_date.value);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		v_url = v_url+ "&" + randomizeNumber();
		
		//alert(v_url);
		sRtn = showModalDialog(v_url,"","dialogWidth=400pt;dialogHeight=250pt;dialogTop=100pt;status=no;scroll=yes;");
		if (!sRtn){ 
			return;
		}else{
			arr_value = sRtn.split(_LIST_DELIMITOR);
			p_hdn_item.value = arr_value[0];
			hdn_date.value = arr_value[1];
			//p_hdn_item.value = v_id_list;
			document.forms(0).fuseaction.value = p_fuseaction_ret;
			//alert(p_fuseaction_ret);
			document.forms(0).submit();
		}
		
	}else{
		alert("Chưa có hồ sơ nào được chọn.");
		return;		
	}
}

//DatCQ 14102008 Phan cong thu ly tai tiep nhan.
function show_modal_dialog_update_onclickDatCQ(p_goto_url,p_fuseaction,p_fuseaction_ret, p_checkbox_item, p_hdn_item,hdn_type,hdn_date,hdn_handler,hdn_record_number_page){
//alert(p_goto_url+"*1*"+p_fuseaction+"*2*"+p_fuseaction_ret+"*3*"+checkbox_value_to_list(p_checkbox_item,",")+"*4*"+p_hdn_item.value+"*5*"+hdn_type.value+"*6*"+hdn_date.value +"*7*");
	var v_id_list = checkbox_value_to_list(p_checkbox_item,",");
	if (v_id_list) {  
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id_list=" + v_id_list + "&hdn_recordtype_filter=" + hdn_type.value+ "&hdn_received_date=" + hdn_date.value+ "&hdn_handler=" + hdn_handler.value+ "&hdn_record_number_page=" + hdn_record_number_page.value);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		v_url = v_url+ "&" + randomizeNumber();
		
		//alert(v_url);
		sRtn = showModalDialog(v_url,"","dialogWidth=400pt;dialogHeight=200pt;dialogTop=100pt;status=no;scroll=yes;");
		if (!sRtn){ 
			return;
		}else{
			arr_value = sRtn.split(_LIST_DELIMITOR);
			p_hdn_item.value = arr_value[0];
			hdn_date.value = arr_value[1];
			hdn_handler.value = arr_value[2];
			document.forms(0).fuseaction.value = p_fuseaction_ret;
			document.forms(0).submit();
		}
		
	}else{
		alert("Chưa có hồ sơ nào được chọn.");
		return;		
	}
}
//DatCQ 14102008 Phan cong thu ly tai tiep nhan.

function show_modal_dialog_update_onclick_nhan_blai_tu_cquan(p_goto_url,p_fuseaction,p_fuseaction_ret, p_checkbox_item, p_hdn_item,hdn_type,hdn_date){
//alert(p_goto_url+"*1*"+p_fuseaction+"*2*"+p_fuseaction_ret+"*3*"+checkbox_value_to_list(p_checkbox_item,",")+"*4*"+p_hdn_item.value+"*5*"+hdn_type.value+"*6*"+hdn_date.value +"*7*");
	var v_id_list = checkbox_value_to_list(p_checkbox_item,",");
	if (v_id_list) {  
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id_list=" + v_id_list + "&hdn_recordtype_filter=" + hdn_type.value+ "&hdn_received_date=" + hdn_date.value);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		v_url = v_url+ "&" + randomizeNumber();
		
		//alert(v_url);
		sRtn = showModalDialog(v_url,"","dialogWidth=400pt;dialogHeight=250pt;dialogTop=100pt;status=no;scroll=no;");
		if (!sRtn){ 
			return;
		}else{
			arr_value = sRtn.split(_LIST_DELIMITOR);
			p_hdn_item.value = arr_value[0];
			hdn_date.value = arr_value[1];
			//p_hdn_item.value = v_id_list;
			document.forms(0).fuseaction.value = p_fuseaction_ret;
			//alert(p_fuseaction_ret);
			document.forms(0).submit();
		}
		
	}else{
		alert("Chưa có hồ sơ nào được chọn.");
		return;		
	}
}
//Leav_add_begin :13/06/2008,update continue :16102008
function show_modal_dialog_update_onclick_tax(p_goto_url,p_fuseaction,p_fuseaction_ret, p_checkbox_item, p_hdn_item,hdn_type,hdn_date,hdn_tax_receiver,hdn_result){
	var v_id_list = checkbox_value_to_list(p_checkbox_item,",");
	var sizeIdrecord;
	if(v_id_list==null ||v_id_list==""){
		sizeIdrecord=0;
	}else{
		var idRecord_arrs=v_id_list.split(",");
		sizeIdrecord=idRecord_arrs.length;
	}
	if (sizeIdrecord==1) {  
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id_list=" + v_id_list + "&hdn_recordtype_filter=" + hdn_type.value+ "&hdn_received_date=" + hdn_date.value+ "&hdn_tax_receiver=" +hdn_tax_receiver.value+"&hdn_txt_result=" +hdn_result.value);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		v_url = v_url+ "&" + randomizeNumber();
		sRtn = showModalDialog(v_url,"","dialogWidth=400pt;dialogHeight=250pt;dialogTop=50pt;status=no;scroll=no;");
		if (!sRtn){ 
			return;
		}else{
			arr_value = sRtn.split(_LIST_DELIMITOR);
			p_hdn_item.value = arr_value[0];
			hdn_date.value = arr_value[1];
			hdn_tax_receiver.value = arr_value[2];
			hdn_result.value = arr_value[3];
			document.forms(0).fuseaction.value = p_fuseaction_ret;
			document.forms(0).submit();
		}
	}else if(sizeIdrecord>1){
		alert("Bạn chỉ được chọn một hồ sơ để trả thông báo cho công dân.");
		return;
	}else{
		alert("Chưa có hồ sơ nào được chọn.");
		return;		
	}
}
//Leav_add_end :13/06/2008
function show_modal_dialog_update_onclick_tax_2(p_goto_url,p_fuseaction,p_fuseaction_ret, p_checkbox_item, p_hdn_item,hdn_type,hdn_date,hdn_tax_receiver,hdn_result,hdn_date_cquan,hdn_receiver_notify_name){
	var v_id_list = checkbox_value_to_list(p_checkbox_item,",");
	var sizeIdrecord;
	if(v_id_list==null ||v_id_list==""){
		sizeIdrecord=0;
	}else{
		var idRecord_arrs=v_id_list.split(",");
		sizeIdrecord=idRecord_arrs.length;
	}
	if (sizeIdrecord==1) {  
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id_list=" + v_id_list + "&hdn_recordtype_filter=" + hdn_type.value+ "&hdn_received_date=" + hdn_date.value+ "&hdn_tax_receiver=" +hdn_tax_receiver.value+"&hdn_txt_result=" +hdn_result.value+"&hdn_txt_date_notify_tu_cquan="+hdn_date_cquan.value+"&hdn_receiver_notify_name="+hdn_receiver_notify_name.value);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		v_url = v_url+ "&" + randomizeNumber();
		sRtn = showModalDialog(v_url,"","dialogWidth=500pt;dialogHeight=300pt;dialogTop=100pt;status=no;scroll=no;");
		if (!sRtn){ 
			return;
		}else{
			arr_value = sRtn.split(_LIST_DELIMITOR);
			p_hdn_item.value = arr_value[0];
			hdn_date.value = arr_value[1];
			hdn_tax_receiver.value = arr_value[2];
			hdn_result.value = arr_value[3];
			hdn_date_cquan.value = arr_value[4];
			hdn_receiver_notify_name.value = arr_value[5];
			document.forms(0).fuseaction.value = p_fuseaction_ret;
			document.forms(0).submit();
		}
	}else if(sizeIdrecord>1){
		alert("Bạn chỉ được chọn một hồ sơ để trả thông báo cho công dân.");
		return;
	}else{
		alert("Chưa có hồ sơ nào được chọn.");
		return;		
	}
}
function btn_update_handover_onclick_2(p_hdn_obj,p_txt_obj){
	if (verify(document.forms(0))){
		window.returnValue = p_hdn_obj.value + _LIST_DELIMITOR + p_txt_obj.value;
		window.close();
	}
}
function btn_update_handover_onclick(p_hdn_obj,p_txt_obj){
	if (verify(document.forms(0))){
		window.returnValue = p_hdn_obj.value + _LIST_DELIMITOR + p_txt_obj.value;
		window.close();
	}
}

//DatCQ 14102008 Phan cong thu ly tai tiep nhan.
function btn_update_handover_onclick_pc(p_hdn_obj,p_txt_obj,p_selectbox_obj){
	if (verify(document.forms(0))){
		window.returnValue = p_hdn_obj.value + _LIST_DELIMITOR + p_txt_obj.value + _LIST_DELIMITOR + p_selectbox_obj.value;
		window.close();
	}
}
//End 14102008 Phan cong thu ly tai tiep nhan.

//
function btn_update_handover_onclick_leav(p_hdn_obj,p_txt_obj,p_receiver_name,p_result,p_date_cquan,p_receiver_notify_name){
	if (verify(document.forms(0))){
		window.returnValue = p_hdn_obj.value + _LIST_DELIMITOR + p_txt_obj.value+ _LIST_DELIMITOR+p_receiver_name.value+_LIST_DELIMITOR+ p_result.value +_LIST_DELIMITOR +p_date_cquan.value +_LIST_DELIMITOR +p_receiver_notify_name.value;
		//alert(window.returnValue);
		window.close();
	}
}
function btn_update_handover_onclick_nhan_bienlai_cquan(p_hdn_obj,p_txt_obj,p_result){
	if (verify(document.forms(0))){
		window.returnValue = p_hdn_obj.value + _LIST_DELIMITOR + p_txt_obj.value+ _LIST_DELIMITOR +_LIST_DELIMITOR+ p_result.value;
		//alert(window.returnValue);
		window.close();
	}
}
//Lay ngay tiep theo cua ngay trong elTerget.value
function Next_Date(p_date) {
	if(isdate(p_date)){
		var theDate,strSeparator,arr,day,month,year;
		strSeparator = "";
		theDate = p_date;
		if (theDate.indexOf("/")!=-1) strSeparator = "/";
		if (theDate.indexOf("-")!=-1) strSeparator = "-";
		if (theDate.indexOf(".")!=-1) strSeparator = ".";
		if (strSeparator != "") {
		arr=theDate.split(strSeparator);
		day=new Number(arr[0])+1;
		month=new Number(arr[1]);
		year=new Number(arr[2]);
		if(day > 28) {
			if (((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day > 31))
			|| ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30))||(month == 2 && year % 4 !=0)||(month == 2 && year % 4 ==0 && day > 29)) 
			{
				day = 1;
				month = month+1;
			}
			if (month > 12 ){
				year = year +1;
				month = 1;
			}
			
		}	
		return day + strSeparator + month + strSeparator + year;
	}
   }		
	
}
function list_have_date(the_list,the_element, the_separator)
{	
	if (the_list=="") return 0;
	arr_value = the_list.split(the_separator);
	for(i=0;i<arr_value.length;i++){
		if (date_compare(arr_value[i],the_element)==0){
			return 1;
		}
	}
	return 0;
}
function get_appoint_date(obj_date_input,count,obj_date_output,p_year){
	var v_list_day_off_of_year = _LIST_DAY_OFF_OF_YEAR.split(",");
	var v_list_day = _LIST_WORK_DAY_OF_WEEK;
	var v_list_luner_date="";
	var v_date,v_temp_date;
	var v_input_date = obj_date_input.value;
	var v_next_date = "";
	var dem=0;
	if (!isdate(obj_date_input.value)){
		return;
	}
	var i=0;
	v_next_date = v_input_date;
	var arr="";
	while ((i<count)){ //Tinh du tong so ngay tru ngay duoc nghi ra
		arr=v_next_date.split("/");
		v_list_luner_date=create_list_luner_day(arr[2]);
		if ((list_have_date(v_list_luner_date,Solar2Lunar(v_next_date),",")!=1)&&(Solar2DayofWeek(v_next_date)!=7)&&(Solar2DayofWeek(v_next_date)!=8)){
			i++;				
			v_next_date = Next_Date(v_next_date);	
		}else{
			//Tinh ngay nghi bu
			if (((list_have_date(v_list_luner_date,Solar2Lunar(v_next_date),",")==1)&&(Solar2DayofWeek(v_next_date)==7))||((list_have_date(v_list_luner_date,Solar2Lunar(v_next_date),",")==1)&& (Solar2DayofWeek(v_next_date)==8))) {
				dem++;
				//alert(dem);
			}
			v_next_date = Next_Date(v_next_date);	
		}		
	}//Neu den han duoc lay roi ma gap ngay khong tiep thi phai cho 
	while ((list_have_element(v_list_day,Solar2DayofWeek(v_next_date),",")<0)){
		v_next_date = Next_Date(v_next_date);	
	}
	obj_date_output.value = v_next_date;
	if (dem!=0)
	{
		//alert(obj_date_output.value+"--"+dem+"--"+arr[2]);
		get_appoint_date(obj_date_output,dem,obj_date_output,arr[2]);
	}
}

function create_list_luner_day(p_year) {
	var v_list_day_off_of_year = _LIST_DAY_OFF_OF_YEAR.split(",");
	var v_list_luner_date = "";
	for (var i=0;i<v_list_day_off_of_year.length;i++){
		v_date = v_list_day_off_of_year[i].split("/");
		if (v_date[0]=="-"){
			v_list_luner_date = list_append(v_list_luner_date,v_date[1]+"/" + v_date[2] + "/" + p_year,",");
		}else{
			v_temp_date = Solar2Lunar(v_date[1]+ "/" + v_date[2] + "/" + p_year);			
			v_list_luner_date = list_append(v_list_luner_date,v_temp_date,",");
		}
	}
	return v_list_luner_date;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//==========================================================================
//Leav _update_begin :070708
function btn_result_handle_onclick(p_checkbox_obj, p_hidden_obj, p_fuseaction){
	//alert('452353534: '+p_fuseaction+"\n"+checkbox_value_to_list(p_checkbox_obj,",") +"\n"+"record_id="+p_hidden_obj.value);
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else{
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		document.forms(0).submit(); 
	}	
}
//nieuvv--161208--chuyen cho can bo luan chuyen ho so
function btn_move_handle_onclick(p_checkbox_obj, p_hidden_obj, p_fuseaction,p_worktype){
	//alert('452353534: '+p_fuseaction+"\n"+checkbox_value_to_list(p_checkbox_obj,",") +"\n"+"record_id="+p_hidden_obj.value);
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else{
		document.forms(0).hdn_worktype.value = p_worktype;
		document.forms(0).fuseaction.value = p_fuseaction;
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		document.forms(0).submit(); 
	}	
}
//the-end-nieuvv--161208--
//----------begin hieudt 081208-------------------------
function btn_result_handle_onclick_hieudt(p_checkbox_obj, p_hidden_obj, p_fuseaction){
	//alert('452353534: '+typeof(checkbox_value_to_list(p_checkbox_obj,",")) +"\n"+"reocrd_id="+p_hidden_obj.value);
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else if(checked_box_length(p_checkbox_obj,",")>1){
		alert("Bạn chỉ được chọn một hồ sơ.");
		return;
	}else{
		document.forms(0).fuseaction.value = p_fuseaction;
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		document.forms(0).submit(); 
	}	
}
//-----------end hieudt 081208-------------------------
//nieuvv--121108-update cong viec dac biet
function btn_result_update_spec(p_checkbox_obj, p_hidden_obj, p_fuseaction){	
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else{
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		document.forms(0).fuseaction.value = p_fuseaction;
		document.forms(0).submit(); 
	}	
}
//the-end-nieuvv--121108---
//DatCQ Hieu chinh de cap nhat noi dung giay phep nhieu ho so 311008
function btn_result_handle_onclick(p_checkbox_obj, p_hidden_obj, p_fuseaction, p_recordtype){
	//alert('452353534: '+p_fuseaction+"\n"+checkbox_value_to_list(p_checkbox_obj,",") +"\n"+"record_id="+p_hidden_obj.value);
	//alert(p_recordtype.value);
	//return;
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else{
		
		//Chi co TT 009 moi cho cap nhat giay phep nhieu ho so!
		if(checked_box_length(p_checkbox_obj,",")>1 && p_fuseaction == 'DISPLAY_SINGLE_LICENSE' && p_recordtype.value == '009'){
			document.forms(0).fuseaction.value = 'DISPLAY_MULTIPLE_LICENSE';
			document.forms(0).hdn_record_id_list.value = checkbox_value_to_list(p_checkbox_obj,",");
		}else{
			document.forms(0).fuseaction.value = p_fuseaction;
		}
		
		//alert(checked_box_length(p_checkbox_obj,",")+"\n"+p_fuseaction);
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		document.forms(0).submit(); 
	}	
}
//DatCQ Hieu chinh de cap nhat noi dung giay phep nhieu ho so 311008

// Kien update 14/08/2008
function btn_result_handle_onclick_kienlt(p_checkbox_obj,p_hidden_obj, p_fuseaction){
	
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else{
		//alert('kien---22');
		var obj_check=checked_box_length(p_checkbox_obj,",");
		//alert('kien---33--'+p_checkbox_obj.value+'---'+typeof(p_checkbox_obj.value));
		//alert(obj_check);
		if(obj_check<=1){
			//alert('kien---'+obj_check);
			document.forms(0).fuseaction.value = p_fuseaction;
			//alert('kien---'+obj_check);
			// p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
			 //alert (p_hidden_obj.value);
		}else{
			document.forms(0).fuseaction.value='DISPLAY_SINGLE_RECORD_WORK_KIEN';
			//list_ p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
			//alert(list_ p_hidden_obj.value);
		}
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		document.forms(0).submit(); 
	}	
}
// End Kien update 14/08/2008
function btn_result_handle_onclick_leav(p_checkbox_obj, p_hidden_obj, p_fuseaction){
	//alert('452353534: '+typeof(checkbox_value_to_list(p_checkbox_obj,",")) +"\n"+"reocrd_id="+p_hidden_obj.value);
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else if(checked_box_length(p_checkbox_obj,",")>1){
		//var list_record_id=checked_box_length(p_checkbox_obj,",");
		//alert('length Test 070708: '+list_record_id);
		alert("Bạn chỉ được chọn một hồ sơ.");
		return;
	}else{
		document.forms(0).fuseaction.value = p_fuseaction;
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		document.forms(0).submit(); 
	}	
}
//Leav _update_end :070708
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Leav_12082008_begin
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name,"",-1);
}
function btn_result_handle_onclick_tranh_chap(p_checkbox_obj,p_hidden_obj){
	//var size_conflict;
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		p_hidden_obj.value=0;
		
	}else{
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
	}	
	eraseCookie('list_of_conflicts');
	createCookie('list_of_conflicts',p_hidden_obj.value,1);
	
}

function save_of_checkbox(obj_save){
	
	obj_save.value=readCookie('list_of_conflicts');
	//alert(obj_save.value);
	}

//Leav_end_12082008
//Leav_begin:15082008
function show_modal_dialog_onclick_view_conflict(id_record_conflict){
	var p_goto_url= 'record/approving/index.php';
	var p_fuseaction='DISPLAY_SINGLE_RECORD_DISPUTE';
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id="+id_record_conflict);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		sRtn = showModalDialog(v_url,"","dialogWidth=600pt;dialogHeight=1000pt;dialogTop=100pt;status=no;scroll=yes;");
		
}
function btn_result_handle_onclick_view_conflict(p_checkbox_obj,p_hidden_obj){
	//var size_conflict;
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert('Không có hồ sơ nào được chọn.');
	}else{
		if(checked_box_length(p_checkbox_obj,",")>1){
			alert('Bạn chỉ được chọn một hồ sơ để xem.');
		}else{
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		show_modal_dialog_onclick_view_conflict(p_hidden_obj.value);
		}
	}	
}

//Leav_end:15082008

//Leav_begin_update_07112008:
//-Phuc vu cho chuc nang Ho So Tranh Chap (Khi click vao 1 HS tranh chap)
function row_onclick_conflict(p_obj, p_value){
	p_obj.value=p_value;
	eraseCookie('list_of_conflicts');
	createCookie('list_of_conflicts',p_obj.value,1);
	window.close();
	
}
//Leav_end_update_07112008
function btn_move_to_leader_onclick(p_checkbox_obj, p_hidden_obj, p_fuseaction){
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chưa có hồ sơ nào được chọn.");
		return;
	}else{
		document.forms(0).fuseaction.value = p_fuseaction;
		p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
		alert("Tất cả các hồ sơ " + p_hidden_obj.value + "sẽ được chuyển cho lãnh đạo.");
		document.forms(0).submit(); 
	}	
}
function sending_email(p_fuseaction){
		document.forms(0).fuseaction.value = p_fuseaction;
		document.forms(0).submit();
}
//Ham nay dung de kiem tra xem co ton tai the xxx khong???
function test_tag(name_tag){
	var v_test_tag = false;
	var f = document.forms(0);
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		var v_element = e.xml_tag_in_db;
		if(v_element != "undefined"){
			if(v_element == name_tag){
				v_test_tag = true;
				break;
			}
		}
	}
	return v_test_tag;
}
//Ham nay dung de kiem tra xem la phan tu "name_element" co ton tai khong?
//Vi du: Kiem tra phan tu co ten la txt_code co ton tai tren form khong?
function test_form_element(name_element){
	var v_test_form_element = false;
	var f = document.forms(0);
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		var v_element = e.name;
		if(v_element != "undefined"){
			if(v_element == name_element){
				v_test_form_element = true;
				break;
			}
		}
	}
	return v_test_form_element;
}
/*
	chuc nang: Ham dung de lay gia tri tu mot the tag_name
	vi du: Muon lay gia tri tu the doc_another
*/
function get_value_from_tag(tag_name){
	var f = document.forms(0);
	var v_value = "";
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		var v_element = e.xml_tag_in_db;
		if(v_element != "undefined"){			
			if(v_element == tag_name){
				v_value = e.value;
				break;
			}
		}
	}
	return v_value;
}
/*
	Chuc nang: Ham dung de cheo vao mot phan tu cua multilcheckbox
*/
/*
function f_checked_multil(tag_name){
	var v_len_checkbox = document.all.chk_item_id.length;
	for(var v_index = 0;v_index<v_len_checkbox;v_index++){
		var v_value = document.all.chk_item_id[v_index].value;
		var v_value_from_tab = get_value_from_tag("doc_another");	
		if((v_value == tag_name) && (v_value_from_tab!="") && (!isblank(v_value_from_tab)) && (v_value_from_tab!=null)){
		//alert(v_value_from_tab);
			document.all.chk_item_id[v_index].checked = true;
		}
	}
			
}
*/
/*
	Chuc nang: Ham nay dung de an/hien khi NSD cho vao muc tai lieu khac tren list tai lieu kem theo
	Vi du: Khi NSD chon vao "Tai lieu khac" tren danh sach tai lieu kem theo
*/
function show_hide_content_doc_another(){
	if(test_tag('doc_another')){
		//f_checked_multil('TAI_LIEU_KHAC');
		var v_count = 0;
		var v_len_checkbox = document.all.chk_item_id.length;
		for(var v_index = 0;v_index<v_len_checkbox;v_index++){
			var v_value = document.all.chk_item_id[v_index].value;
			if((v_value == 'TAI_LIEU_KHAC') && (document.all.chk_item_id[v_index].checked)){
				v_count++;
				document.forms(0).hdn_doc_another.value = 1;
				show_row('doc_another');
				break;
			}
		}
		//alert(v_count);
		if(v_count <= 0){
			document.forms(0).hdn_doc_another.value = 0;
			hide_row('doc_another');
		}
	}
}
//Ham nay thuc thi khi NSD nhan vao mot trang tren danh sach
function page_onchange(sel_obj,p_fuseaction){
	document.forms(0).hdn_page.value = sel_obj.value;	
	document.forms(0).fuseaction.value = p_fuseaction;
	document.forms(0).submit();
}
//Ham nay thuc thi khi NSD muon thay doi so dong quy dinh tren mot trang
function page_record_number_onchange(sel_obj,p_fuseaction){
	document.forms(0).hdn_page.value = 1;
	document.forms(0).hdn_record_number_page.value = sel_obj.value;
	document.forms(0).fuseaction.value = p_fuseaction;
	document.forms(0).submit();
}
//nieuvv--270808---show danh sach can bo thu ly 
function show_dialog_all_item_onclick(p_goto_url,p_fuseaction, p_text_name_obj, p_text_code_obj, p_hdn_obj, p_hdn_unit_id,p_hdn_handler_id_list){
	if (p_hdn_unit_id == ''){
	 alert ('Phải xác định phòng thụ lý hồ sơ.'); return;
	}
	//alert(p_hdn_unit_id);
	v_url =  p_goto_url + "?hdn_handle_agency_id="+p_hdn_unit_id +"&hdn_handler_id_list="+p_hdn_handler_id_list + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" + "&" + randomizeNumber();
	//alert(v_url);return;
	sRtn = showModalDialog(v_url,"","dialogWidth=420pt;dialogHeight=280pt;dialogTop=80pt;status=no;scroll=yes;");
	if (!sRtn) return;
	arr_value = sRtn.split(_LIST_DELIMITOR);
	p_hdn_obj.value = arr_value[0];
	p_text_code_obj.value = arr_value[1];		
	p_text_name_obj.value = arr_value[2];
	}
// end nieuvv----270808---
//nieuvv--181008-sort du lieu dung jQuery


var c_id = new Array();						// stt
var c_code = new Array();				// ma ho so
var register_name = new Array();		// ten nguoi dai dien
var c_address = new Array();			// dia chi
var c_received_date = new Array();		// ngay tiep nhan
var c_appointed_date = new Array();		// ngay hen tra
var c_current_status = new Array();		// trang thai
var c_cmnd = new Array();				// so cmnd
var c_handle = new Array();				// can bo thu ly
var hiddens = new Array();

// luu du lieu 
// num_record: tong so record 
// num_col : tong so cot
function saveData(num_record,num_col)
{		
	var hidden = document.getElementById('hdn_id');
	hiddens[0] = hidden.value;
	
	hidden = document.getElementById('hdn_code');
	hiddens[1] = hidden.value;
	
	hidden = document.getElementById('hdn_name');
	hiddens[2] = hidden.value;
	
	hidden = document.getElementById('hdn_address');
	hiddens[3] = hidden.value;
	
	hidden = document.getElementById('hdn_received');
	hiddens[4] = hidden.value;

	hidden = document.getElementById('hdn_cmnd');
	hiddens[5] = hidden.value;
	//Lay du lieu hien co tren table
	var index ;
	for( index = 0 ; index < num_record ; index++)
	{		
		var x = document.getElementById(index*num_col + 0);//id cua cac td!
		c_id[index] = x.innerHTML;		
		//alert(c_id[index]);
		
		x = document.getElementById(index*num_col + 1);//id cua cac td!
		c_code[index] = x.innerHTML;
		//alert(c_code[index]);
		
		x = document.getElementById(index*num_col + 2 );
		register_name[index] = x.innerHTML;	
		//alert(register_name[index]);
		
		x = document.getElementById(index*num_col + 3 );
		c_address[index] = x.innerHTML;		
		//alert(c_address[index]);
		
		x = document.getElementById(index*num_col + 4 );
		c_received_date[index] = x.innerHTML;
		//alert(c_received_date[index]);
		if(num_col>5)
		{
			x = document.getElementById(index*num_col + 5 );
			c_cmnd[index] = x.innerHTML;
			//alert(c_cmnd[index]);
		}		
	}		
}
//hien thi danh sach ho so sau khi sap xep
function ShowData(num_record,num_col)
{
	var hidden = document.getElementById('hdn_id');
	hidden.value = hiddens[0];
	
	hidden = document.getElementById('hdn_code');
	hidden.value = hiddens[1];
	
	hidden = document.getElementById('hdn_name');
	hidden.value = hiddens[2];
	
	hidden = document.getElementById('hdn_address');
	hidden.value = hiddens[3];
	
	hidden = document.getElementById('hdn_received');
	hidden.value = hiddens[4];

	hidden = document.getElementById('hdn_cmnd');
	hidden.value = hiddens[5];
	var ind ;
	for( ind = 0 ; ind < num_record ; ind++)
	{	
		var x = document.getElementById(ind*num_col + 0);//id cua cac td!
		x.innerHTML = c_id[ind];
		
		x = document.getElementById(ind*num_col + 1);//id cua cac td!
		x.innerHTML =c_code[ind] ; 
		
		x = document.getElementById(ind*num_col + 2 );
		x.innerHTML = register_name[ind];
		
		x = document.getElementById(ind*num_col + 3 );
		x.innerHTML = c_address[ind];
		
		x = document.getElementById(ind*num_col + 4 );
		x.innerHTML = c_received_date[ind];
		if(num_col > 5){
			x = document.getElementById(ind*num_col + 5 );
			x.innerHTML = c_cmnd[ind];
		}
	//	x = document.getElementById(i*10 + 5 );
	//	c_appointed_date[i] = x.innerHTML;
	}
}
// hoan doi dong
function ExchangeRow(i,j)
{
	
	var temp_arrang;
	
	temp_arrange = c_id[i];
	c_id[i] = c_id[j];
	c_id[j] = temp_arrange;
	// hoan vi ma ho so
	temp_arrange = c_code[i];
	c_code[i] = c_code[j];
	c_code[j] = temp_arrange;
	// hoan vi ten nguoi dai dien
	temp_arrange = register_name[i];
	register_name[i] = register_name[j];
	register_name[j] = temp_arrange;
	// hoan vi dia chi
	temp_arrange = c_address[i];
	c_address[i] = c_address[j];
	c_address[j] = temp_arrange;
	// hoan vi ngay hen tra
	temp_arrange = c_appointed_date[i];
	c_appointed_date[i] = c_appointed_date[j];
	c_appointed_date[j] = temp_arrange;
	
	temp_arrange = c_received_date[i];
	c_received_date[i] = c_received_date[j];
	c_received_date[j] = temp_arrange;
	
	temp_arrange = c_cmnd[i];
	c_cmnd[i] = c_cmnd[j];
	c_cmnd[j] = temp_arrange;
}

// so sanh theo ten nguoi dai dien
// tra ve 1 : name1 > name2
// tra ve 0 : name1 = name2
// tra ve -1 : name1 < name2
function CompareName(name1,name2)
{	
	var ht1 = new Array();
	ht1 = name1.split(" ");
	var ht2 = new Array();
	ht2 = name2.split(" ");
	var i,j;
	var len1 = ht1.length;
    var len2 = ht2.length;

	//dau tien so sang ten truoc 
	if( ht1[len1-1] > ht2[len2-1])//du 1 khoang trang cuoi cung cua hoten ?
		return 1;
	else if( ht1[len1 -1] == ht2[len2-1])
	{            
		for(i = 0 ; i < len1 ; i ++)
		{
			if(ht1[i] > ht2[i])
				return 1;
			else if(ht1[i] == ht2[i])
				return 0;
			else
				return -1;
		}
	}     
	else if( ht1[len1-1] < ht2[len2-1])
		return -1;	
}
// so sanh so cmnd
// tra ve 1: cmnd1 > cmnd2 
// tra ve 0: cmnd1 = cmnd2
// tra ve -1: cmnd1 < cmnd1
function CompareCMND(cmnd1,cmnd2)
{
	if(cmnd1 > cmnd2)
		return 1;
	else if(cmnd1 == cmnd2)
		return 0;
	else
		return -1;
}
//so sanh theo ma ho so
// tra ve 1 : code1 > code2
// tra ve 0 : code1 = code2
// tra ve -1: code1 < code2
function CompareCode(code1,code2)
{
	var c1 = new Array();
	c1 = code1.split(".");
	var c2 = new Array();
	c2 = code2.split(".");
	var len1 = c1.length;
	var len2 = c2.length;
	var i,j;
	if(c1[len1-2] > c2[len2-2]) 	// du khoang trang cuoi cung
		return 1;
	else if(c1[len1-1] == c2[len2-1])
	{
		for(i = 0 ; i < len1; i++ )
		{
			if(c1[i] > c2[i])
				return 1;
			else if(c1[i] == c2[i])
				return 0;
			else
				return -1;
		}
	}
	else 
		return -1;
}
// so sanh theo ngay 
// tra ve 1: date1 > date2
// tra ve 0: date1 = date2
// tra ve -1: date1< date2
function CompareDate(date1,date2)
{
//	alert(date1);
	//alert(date2);
	var dt1 = new Array();
	var dt2 = new Array();
	dt1 = date1.split("/");		// tach ra bang dau '/'
	dt2 = date2.split("/");
	var nam1 , nam2,thang1,thang2,ngay1,ngay2;
	nam1 = Math.abs(dt1[2]);//chuyen tu kieu chuoi sang so de so sanh!
	nam2 = Math.abs(dt2[2]);
	thang1 = Math.abs(dt1[1]);
	thang2 = Math.abs(dt2[1]);
	ngay1 =  Math.abs(dt1[0]);
	ngay2 = Math.abs(dt2[0]);
	
	if(nam1 > nam2)
		return 1;
	else if( nam1 == nam2)
	{
		if(thang1 > thang2)//javascrip so sanh bi sai ngay day!
			return 1;
		else if( thang1 == thang2)
		{
			if( ngay1 > ngay2 )
				return  1;
			else if ( ngay1 == ngay2)
				return 0;
			else 
				return -1;        
		}    
		else 
			return -1;        
	}
	else 
		return -1;
}
// sap xep theo ma ho so
function SortByCode(num_record,num_col)
{	
	saveData(num_record,num_col);		// luu du lieu		
	if(hiddens[1] == 1)			// hidden cua ma ho so
	{
		hiddens[1] = 0;		
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {			
			  if( CompareCode(c_code[j],c_code[i]) <= 0)
			  {
				ExchangeRow(i,j);			 
			  }
		  }		
	}
	else			// nguoc lai hidden = 0 :sap giam
	{
		hiddens[1] = 1;	
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {			
			  if( CompareCode(c_code[j],c_code[i]) > 0)
			  {
				ExchangeRow(i,j);			 
			  }
		  }		
	}	
	ShowData(num_record,num_col);
}
// sap xep theo ten nguoi dai dien
function SortByName(num_record,num_col)
{	
	saveData(num_record,num_col);		// luu du lieu
	if(hiddens[2] == 1)			// hidden cua ma ho so: = 1: sap tang
	{
		hiddens[2] = 0;
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {			
			  if( CompareName(register_name[j],register_name[i]) <= 0)
			  {
					ExchangeRow(i,j);			 
			  }
		  }		
	}
	else			// nguoc lai hidden = 0 :sap giam
	{
		hiddens[2] = 1;	
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {
			  if( CompareName(register_name[j],register_name[i]) > 0)
			  {
				ExchangeRow(i,j);			 
			  }
		  }		
	}	
	ShowData(num_record,num_col);
}
// sap xep theo ngay thang
function SortByDate(num_record,num_col)
{
	saveData(num_record,num_col);		// luu du lieu
	if(hiddens[4] == 1)			// hidden cua ma ho so: = 1: sap tang
	{
		hiddens[4] = 0;
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {			
			  if(CompareDate(c_received_date[j],c_received_date[i]) <= 0)
			  {
				ExchangeRow(i,j);			 
			  }
		  }		
	}
	else			// nguoc lai hidden = 0 :sap giam
	{
		hiddens[4] = 1;	
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {			
			  if(CompareDate(c_received_date[j],c_received_date[i]) > 0)
			  {
				ExchangeRow(i,j);			 
			  }
		  }		
	}	
	ShowData(num_record,num_col);
}
// sap xep theo cmnd
function SortByCMND(num_record,num_col)
{
	saveData(num_record,num_col);
	if(hiddens[5] == 1)
	{
		hiddens[5] = 0;
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {			
			  if(CompareCMND(c_received_date[j],c_received_date[i]) <= 0)
			  {
				ExchangeRow(i,j);			 
			  }
		  }		
	}
	else
	{
		hiddens[5] = 1;	
		var i ,j ;
		for(i  = 0 ; i < num_record-1 ; i++)
		  for( j = i+ 1 ; j < num_record ; j++)
		  {			
			  if(CompareCMND(c_received_date[j],c_received_date[i]) > 0)
			  {
				ExchangeRow(i,j);			 
			  }
		  }		
	}
	ShowData(num_record,num_col);
}
// sap xep tong quat
function Arange(p_type,num_record,num_col)
{
	//alert(p_type);
	switch(p_type)
	{
		case 1:
			//alert("1");
			SortByCode(num_record,num_col);
			break;
		case 2:
			//alert("2");
			SortByName(num_record,num_col);
			break;
		case 3:
			//alert("3");			
			SortByName(num_record,num_col);
			break;
		case 4:
			//alert("4");
			SortByDate(num_record,num_col);
			break;
		case 3,5:
			//alert("5");			
			SortByCMND(num_record,num_col);
			break;
		default:
			//alert("6");
			SortByName(num_record,num_col);
			break;
	}		
}

var xmlHttp_sort;
function createXMLHttpSortRequest() {
	if (window.ActiveXObject) {
		xmlHttp_sort = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp_sort = new XMLHttpRequest();
	}
}

function arrange_list(column_name, xml_tag_in_data, xml_data, fuseaction, v_staff_id, 
    v_recordtype_filter, 
	v_receive_date_filter, 
	v_status_list,
	v_role,
	v_status_of_handover,
	v_status_of_assigning,
	v_status_of_handle_approve,
	v_status_of_chaiman_approve,
	v_order_clause,
	v_sort_type,
	v_detail_status_compare,
	v_page,
	v_limit_row,
	v_status_compare,
	v_values,
	v_name_ben_a,
	v_name_ben_b,
	v_handler_name,
	v_values_,
	v_values_record_id,
	v_from_receive_date,
	v_to_receive_date,
	v_from_result_date,
	v_to_result_date,
	v_tu_ngay,
	v_den_ngay) {
        if (xml_data == 'true') {
			v_order_clause = xml_tag_in_data + ',true,' + v_sort_type;			
        } else {
			v_order_clause = column_name + ',false,' + v_sort_type;
		}		
		//alert(v_order_clause);
		createXMLHttpSortRequest();
		xmlHttp_sort.onreadystatechange = handleStateChange_sort;
		try {
			//alert(v_order_clause);
			//alert(fuseaction);
			xmlHttp_sort.open("get", "index.php?hdn_received_date_filter="+v_receive_date_filter
				                            +"&hdn_order_clause="+encodeURI(v_order_clause)
											+"&hdn_sort_type="+v_sort_type
				                            +"&hdn_page="+v_page
				                            +"&hdn_record_number_page="+v_limit_row
				                            +"&ho_ten="+encodeURI(v_values)
				                            +"&ben_a="+encodeURI(v_name_ben_a)
				                            +"&ben_b="+encodeURI(v_name_ben_b)
				                            +"&can_bo_thu_ly="+encodeURI(v_handler_name)
				                            +"&record_id_search="+v_values_record_id
				                            +"&from_receive_date="+v_from_receive_date
				                            +"&to_receive_date="+v_to_receive_date
				                            +"&from_appointed_date="+v_from_result_date
				                            +"&to_appointed_date="+v_to_result_date
											+"&ho_ten_nguoi_nhap="+encodeURI(v_values_)
											+"&tu_ngay="+v_tu_ngay
											+"&den_ngay="+v_den_ngay
				                            +"&fuseaction="+fuseaction
				                            +"&is_sort=true"
			                                +"&modal_dialog_mode=1"
											+"&column_name="+column_name
											+"&xml_tag_in_data="+xml_tag_in_data
											+"&xml_data="+xml_data, handleStateChange_sort);												
			xmlHttp_sort.send(false);		
		} catch(err) {
			alert(err.message);
		}		
}

function handleStateChange_sort() {
	if(xmlHttp_sort.readyState==1) {
		//document.getElementById("content").innerHTML = "";		
		document.getElementById("load").style.display = "block";		
	}
	if(xmlHttp_sort.readyState == 4) {
		if(xmlHttp_sort.status == 200) {
			//alert(xmlHttp_sort.responseText );
			var find_str = "<!--dung cho sort (khong duoc xoa hay hieu chinh dong comment nay)-->";
			var str = xmlHttp_sort.responseText;
			//var content_str = str;
			var content_str = str.substr(str.indexOf(find_str) + find_str.length, str.lastIndexOf(find_str));
			//alert(str.indexOf(find_str));
			//alert(str.lastIndexOf(find_str));
			//alert(content_str);
				document.getElementById("sort_content").innerHTML = content_str;
				a();
			document.getElementById("load").style.display = "none";		
		}
	}
}